﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyConsoleApp1
{
    public class SQLdbHelper
    {
        private static readonly string connectionString = "server=.;database=StudentInfo;uid=sa;pwd=qaz888838";

        //直接显示数据库数据
        public static void Query(string CmdString)
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);
            
            using(SqlCommand ass = new SqlCommand(CmdString, sqlConnection))
            {
               
                sqlConnection.Open();

                var status = ass.ExecuteReader();
                while (status.Read())
                {
                    Console.WriteLine("{0}\t{1}\t{2}", status[0], status[1], status[2]);
                }
            }
            
        }
        //添加、删除、修改
        public static int Operate (string Cmdstring)
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);

            using(SqlCommand ass = new SqlCommand(Cmdstring, sqlConnection))
            {
                
                sqlConnection.Open();

                return ass.ExecuteNonQuery();
            }
        }
        //老胡没时间教的，自学的，看看行不行
        public static int Operate1(string Cmdstring)
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);

            using (SqlCommand ass = new SqlCommand(Cmdstring, sqlConnection))
            {
                SqlDataAdapter da = new SqlDataAdapter(ass);

                DataSet ds = new DataSet();

               return  da.Fill(ds, "userRegister");
            }
        }
    }
}
